<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jsp/include/taglibs.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title><%=system_name%> - 订单添加</title>
	<%@include file="/WEB-INF/jsp/include/meta.jsp"%>
	
	<link href="<%=basePath%>css/common.css" rel="stylesheet" type="text/css" />
	<script src="<%=basePath%>js/common.js" type="text/javascript"></script>
	<link href="<%=basePath%>css/public.css" rel="stylesheet" type="text/css">
	<link href="<%=basePath%>css/index.css" rel="stylesheet" type="text/css">
	
	<script type="text/javascript" src="js/pagebar.js"></script>
	<script type="text/javascript" src="fram/engine.js" ></script>
	<script type="text/javascript" src="fram/util.js" ></script>
	<script type="text/javascript" src="fram/interface/orderService.js"></script>
	<script type="text/javascript" src="<%=basePath%>js/DatePicker/WdatePicker.js" defer="defer"></script>
	
	<script type="text/javascript">
	function beforeSubmit(){			
		var userName=$("user.id").value;
		var orderCode=$("orderCode").value;
		if(""==userName){alert("请选择业务员!");return false;}
		if(""==orderCode){alert("请填写合同号!");return false;}		
		//if(productNo.length>100){alert("货号长度不能超过100个字");return false;}
		//if($N("unit")[0].value.length>50){alert("计量单位不能操作50个字");return false;}
		//if($N("details")[0].value.length>300){alert("船方自购物料不能操作300个字");return false;}
		//if($N("remark")[0].value.length>300){alert("备注不能操作300个字");return false;}
		
		return true;
	}
	function browseSupplier(){
		openWindow("<%=basePath%>trade/showSupplierList?"+Math.random());
	}
	function openWindow(url){        
		if (navigator.appVersion.indexOf("MSIE") == -1){
			window.open(url,'newWin','modal=yes,width=510,height=440,top=200,left=300,resizable=no,depended=yes,scrollbars=no');
	        return;
	    }else{
	    	if(navigator.appVersion.match(/MSIE ([\d.]+)/)[1]=='6.0'){
	    		showModalDialog(url,window,'dialogWidth:530px;dialogHeight:490px;')
	    	}else{
	        	showModalDialog(url,window,'dialogWidth:510px;dialogHeight:440px;')
	        }
	    }
	}
	function browsBack(id,name){
		$("cooperFactory").value=name;
		//$("supplier.id").value=id;
	}
	</script>
</head>

<body oncontextmenu='return false'>
<form:form action="" method="post" name="myform" onsubmit="return beforeSubmit();">	
	<!--right begin-->
    <div class="fl right">
    
    		<!--产品详细信息 begin-->	
    		<div class="titleBg">
            	<div class="fl"><img src="images/rightTitleLeft.jpg" alt="left" /></div>
            	<div class="fl title"><span class="marking1"></span>订单信息</div>
                <div class="fr"><img src="images/rightTitleRight.jpg" alt="left" /></div>
            </div>
            <div id="clear"></div>
            
            <div class="rightBorder">
            
                <div class="property1">
                <table width="100%" border="0" cellspacing="1" cellpadding="5" bgcolor="#dfe5e9">
                   <tr>
                    <td width="8%" align="right" bgcolor="#dfe5e9">业务员：</td>
                    <th width="24%" align="left" bgcolor="#dfe5e9">
                    	<c:choose>
                    		<c:when test="${sessionScope.memberSessionInfo.userType.value eq '2'}">
                    		<form:hidden path="user.id" id="user.id"/>${command.user.userName}
                    		</c:when>
                    		<c:otherwise>
                    			<form:select path="user.id">		
								<form:option value="" label="--请选择--"/>
								<form:options items="${userList}" itemLabel="userName" itemValue="id"/>
								</form:select>	
                    		</c:otherwise>
                    	</c:choose>		
                    </th>                        
                    <td width="8%" align="right" bgcolor="#dfe5e9">合同号：</td>
                    <th width="35%" align="left" bgcolor="#dfe5e9" colspan="3"><input type="text" name="orderCode" id="orderCode" value="${command.orderCode}" size="35" class="input" maxlength="20"/></th>
                    <td width="10%" align="right">&nbsp;</td>
                    <th width="15%" align="left" bgcolor="#dfe5e9">&nbsp;</th>                    
                  </tr>
                  <tr>
                    <td width="8%" align="right" bgcolor="#dfe5e9">客户国家：</td>
                    <th width="24%" align="left" bgcolor="#dfe5e9"><input type="text" name="customerCountry" id="customerCountry" value="${command.customerCountry}" size="25" class="input" maxlength="100"/></th>                        
                    <td width="8%" align="right" bgcolor="#dfe5e9">总金额：</td>
                    <th width="10%" align="left" bgcolor="#dfe5e9"><input type="text" name="totalAmount" id="totalAmount" value="${command.totalAmount}" size="15" class="input" maxlength="10"/></th>
                    <td width="10%" align="right">价格术语：</td>
                    <th width="15%" align="left" bgcolor="#dfe5e9"><input type="text" name="priceTerms" id="priceTerms" value="${command.priceTerms}" size="15" class="input" maxlength="30"/></th>
                    <td width="10%" align="right">成交方式：</td>
                    <th width="15%" align="left" bgcolor="#dfe5e9"><input type="text" name="transactionMethod" id="transactionMethod" value="${command.transactionMethod}" size="15" class="input" maxlength="20"/></th>                    
                  </tr>                    
                  <tr>
                    <td align="right">客户公司：</td>
                    <th align="left"><input type="text" name="customerCompany" id="customerCompany" value="${command.customerCompany}" size="25" class="input" maxlength="100"/></th>
                    <td align="right">总件数：</td>
                    <th align="left" bgcolor="#dfe5e9"><input type="text" name="totalNumber" id="totalNumber" value="${command.totalNumber}" size="15" class="input" maxlength="10"/></th>
                    <td align="right">成交日期：</td>
                    <th align="left"><form:input path="closingDate" maxlength="10" size="15" cssClass="input" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/></th>
                    <td width="10%" align="right">出货日期：</td>
                    <th align="left" bgcolor="#dfe5e9"><form:input path="dateShipment" maxlength="10" size="15" cssClass="input" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/></th>                    
                  </tr>
                  <tr>
                    <td align="right">客户名字：</td>
                    <th align="left"><input type="text" name="customerName" id="customerName" value="${command.customerName}" size="25" class="input" maxlength="100"/></th>
                    <td align="right">总毛重：</td>
                    <th align="left"><input type="text" name="grossWeight" id="grossWeight" value="${command.grossWeight}" size="15" class="input" maxlength="10"/></th>
                    <td align="right">出货口岸：</td>
                    <th align="left"><input type="text" name="startShipment" id="startShipment" value="${command.startShipment}" size="15" class="input" maxlength="100"/></th>
                    <td width="10%" align="right">订单状态：</td>
                    <th align="left" bgcolor="#dfe5e9">
                    	<form:select path="status.id">		
						<form:option value="" label="--请选择--"/>
						<form:options items="${statusList}" itemLabel="codeName" itemValue="id"/>
						</form:select>
					</th>
                  </tr>
                  <tr>
                    <td align="right">客户等级：</td>
                    <th align="left">
						<form:select path="customerGrade.id">		
						<form:option value="" label="--请选择--"/>
						<form:options items="${gradeList}" itemLabel="codeName" itemValue="id"/>
						</form:select>						
					</th>
                    <td align="right">总体积：</td>
                    <th align="left"><input type="text" name="totatlVolume" id="totatlVolume" value="${command.totatlVolume}" size="15" class="input" maxlength="10"/></th>
                    <td align="right">运抵口岸：</td>
                    <th align="left"><input type="text" name="endShipment" id="endShipment" value="${command.endShipment}" size="15" class="input" maxlength="100"/></th>
                    <td width="10%" align="right">订单打分：</td>
                    <th align="left" bgcolor="#dfe5e9"><input type="text" name="scoring" id="scoring" value="${command.scoring}" size="15" class="input" maxlength="10"/>分</th>                  
                  </tr>
                  <tr>
                  	<td width="10%" align="right" bgcolor="#dfe5e9">备注</td>
                  	<th width="90%" align="left" bgcolor="#dfe5e9" colspan="7"><textarea name="detail1" class="input" id="detail1" rows="2" cols="120">${command.detail1}</textarea></th>
                  </tr>
                  </table>                
      			  </div>
          	  <div id="clear"></div>            
            </div>
            <!--产品详细信息 end-->
            
            <!--产品详细信息 begin-->	
    		<div class="titleBg">
            	<div class="fl"><img src="images/rightTitleLeft.jpg" alt="left" /></div>
            	<div class="fl title"><span class="marking1"></span>客户收款情况</div>
                <div class="fr"><img src="images/rightTitleRight.jpg" alt="left" /></div>
            </div>
            <div id="clear"></div>
            
            <div class="rightBorder">
            
                <div class="property1">
                <table width="100%" border="0" cellspacing="1" cellpadding="5" bgcolor="#dfe5e9">
                      <tr>
                        <td width="25%" align="right" bgcolor="#dfe5e9" colspan="2">客户第1次付款：</td>
                        <td width="25%" align="right" bgcolor="#dfe5e9" colspan="2">客户第2次付款：</td>
                        <td width="25%" align="right" colspan="2">客户第3次付款：</td>
                        <td width="25%" align="right" colspan="2">客户第4次付款：</td>                                                
                      </tr>                    
                  <tr>
                    <td align="right" width="12%">付款金额：</td>
                    <th align="left" width="13%"><input type="text" name="paymentAmount1" id="paymentAmount1" value="${command.paymentAmount1}" size="10" class="input" maxlength="10"/></th>
                    <td align="right" width="12%">付款金额：</td>
                    <th align="left" width="13%"><input type="text" name="paymentAmount2" id="paymentAmount2" value="${command.paymentAmount2}" size="10" class="input" maxlength="10"/></th>
                    <td align="right" width="12%">付款金额：</td>
                    <th align="left" width="13%"><input type="text" name="paymentAmount3" id="paymentAmount3" value="${command.paymentAmount3}" size="10" class="input" maxlength="10"/></th>
                    <td align="right" width="12%">付款金额：</td>
                    <th align="left" width="13%"><input type="text" name="paymentAmount4" id="paymentAmount4" value="${command.paymentAmount4}" size="10" class="input" maxlength="10"/></th>                                        
                  </tr>
                  <tr>
                    <td align="right">银行费用：</td>
                    <th align="left"><input type="text" name="bankCharges1" id="bankCharges1" value="${command.bankCharges1}" size="10" class="input" maxlength="10"/></th>
                    <td align="right">银行费用：</td>
                    <th align="left" bgcolor="#dfe5e9"><input type="text" name="bankCharges2" id="bankCharges2" value="${command.bankCharges2}" size="10" class="input" maxlength="10"/></th>
                    <td align="right">银行费用：</td>
                    <th align="left"><input type="text" name="bankCharges3" id="bankCharges3" value="${command.bankCharges3}" size="10" class="input" maxlength="10"/></th>
                    <td align="right">银行费用：</td>
                    <th align="left"><input type="text" name="bankCharges4" id="bankCharges4" value="${command.bankCharges4}" size="10" class="input" maxlength="10"/></th>                    
                  </tr>
                  <tr>
                    <td align="right">实际收入：</td>
                    <th align="left"><input type="text" name="realIncome1" id="realIncome1" value="${command.realIncome1}" size="10" class="input" maxlength="10"/></th>
                    <td align="right">实际收入：</td>
                    <th align="left" bgcolor="#dfe5e9"><input type="text" name="realIncome2" id="realIncome2" value="${command.realIncome2}" size="10" class="input" maxlength="10"/></th>
                    <td align="right">实际收入：</td>
                    <th align="left"><input type="text" name="realIncome3" id="realIncome3" value="${command.realIncome3}" size="10" class="input" maxlength="10"/></th>
                    <td align="right">实际收入：</td>
                    <th align="left"><input type="text" name="realIncome4" id="realIncome4" value="${command.realIncome4}" size="10" class="input" maxlength="10"/></th>
                  </tr>
                  <tr>
                    <td align="right">结汇收入：</td>
                    <th align="left"><input type="text" name="exchangeIncome1" id="exchangeIncome1" value="${command.exchangeIncome1}" size="10" class="input" maxlength="10"/></th>
                    <td align="right">结汇收入：</td>
                    <th align="left" bgcolor="#dfe5e9"><input type="text" name="exchangeIncome2" id="exchangeIncome2" value="${command.exchangeIncome2}" size="10" class="input" maxlength="10"/></th>
                    <td align="right">结汇收入：</td>
                    <th align="left"><input type="text" name="exchangeIncome3" id="exchangeIncome3" value="${command.exchangeIncome3}" size="10" class="input" maxlength="10"/></th>
                    <td align="right">结汇收入：</td>
                    <th align="left"><input type="text" name="exchangeIncome4" id="exchangeIncome4" value="${command.exchangeIncome4}" size="10" class="input" maxlength="10"/></th>
                  </tr>
                  <tr>
                    <td align="right">收款账户：</td>
                    <th align="left"><input type="text" name="customerAccount1" id="customerAccount1" value="${command.customerAccount1}" size="10" class="input" maxlength="10"/></th>
                    <td align="right">收款账户：</td>
                    <th align="left" bgcolor="#dfe5e9"><input type="text" name="customerAccount2" id="customerAccount2" value="${command.customerAccount2}" size="10" class="input" maxlength="10"/></th>
                    <td align="right">收款账户：</td>
                    <th align="left"><input type="text" name="customerAccount3" id="customerAccount3" value="${command.customerAccount3}" size="10" class="input" maxlength="10"/></th>
                    <td align="right">收款账户：</td>
                    <th align="left"><input type="text" name="customerAccount4" id="customerAccount4" value="${command.customerAccount4}" size="10" class="input" maxlength="10"/></th>
                  </tr>
                  <tr>
                    <td align="right">时间：</td>
                    <th align="left"><form:input path="paymentTime1" size="10" maxlength="10" cssClass="input" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/></th>
                    <td align="right">时间：</td>
                    <th align="left" bgcolor="#dfe5e9"><form:input path="paymentTime2" maxlength="10" size="10" cssClass="input" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/></th>
                    <td align="right">时间：</td>
                    <th align="left"><form:input path="paymentTime3" maxlength="10" size="10" cssClass="input" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/></th>
                    <td align="right">收时间：</td>
                    <th align="left"><form:input path="paymentTime4" maxlength="10" size="10" cssClass="input" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/></th>
                  </tr>
                  <tr>
                  	<td width="10%" align="right" bgcolor="#dfe5e9">备注</td>
                  	<th width="90%" align="left" bgcolor="#dfe5e9" colspan="7"><textarea name="detail2" class="input" id="detail2" rows="2" cols="120">${command.detail2}</textarea></th>
                  </tr>
                  </table>                
      			  </div>
          	  <div id="clear"></div>            
            </div>
            <!--产品详细信息 end-->
         	
         	<!--统计 end-->
            <div class="total">
                
                <div class="fr Operating">                
                    <ul>
                        <li><input name="提交" type="submit" class="button" value="提交" /></li>
                        <li><input name="重置" type="reset" class="button" value="重置" /></li>
                      
                   </ul>
                </div>
            </div>
            
            
         	<!--产品详细信息 begin-->	
    		<div class="titleBg">
            	<div class="fl"><img src="images/rightTitleLeft.jpg" alt="left" /></div>
            	<div class="fl title"><span class="marking1"></span>工厂付款情况&nbsp;&nbsp;
            		<input name="添 加" type="button" class="button" value="添 加" onclick="addFactory()"/>
            		<input name="修 改" type="button" class="button" value="修 改" onclick="editFactorys()"/>
            		<input name="删 除" type="button" class="button" value="删 除" onclick="delsellMultiple()"/>
            	</div>
                <div class="fr"><img src="images/rightTitleRight.jpg" alt="left" /></div>
            </div>
            <div id="clear"></div>
            
            <div class="rightBorder">
            
                <div class="property1">
                <table width="100%" border="0" cellspacing="1" cellpadding="5" bgcolor="#dfe5e9">
                  <tr>
                  	<th width="3%" align="center"><input type="checkbox" name="fallSelectId" id="fallSelectId" onclick="judgmentChecjBox('fallSelectId','fid')" /></th>
                    <td width="20%" align="center" bgcolor="#dfe5e9">合作工厂</td>
                    <td width="13%" align="center" bgcolor="#dfe5e9">合同总金额</t>                        
                    <td width="8%" align="center" bgcolor="#dfe5e9">价格条款</td>
                    <td width="8%" align="center" bgcolor="#dfe5e9">第1次付款</td>
                    <td width="8%" align="center">时间</td>
                    <td width="8%" align="center" bgcolor="#dfe5e9">第2次付款</td>
                    <td width="8%" align="center">时间</td>
                    <td width="8%" align="center" bgcolor="#dfe5e9">第3次付款</td>
                    <td width="8%" align="center">时间</td>
                    <td width="8%" align="center" bgcolor="#dfe5e9">退税收入</td>
                  </tr>                    
                  <c:forEach var="data" items="${command.factoryList}">
                  <tr>
                    <th align="left"><input type="checkbox" value="${data.id}" name="fid"/></th>
                    <th align="left">${data.cooperFactory}</th>
                    <th align="left">${data.amount}</th>
                    <th align="left">${data.terms}</th>
                    <th align="left">${data.payment1}</th>
                    <th align="left"><fmt:formatDate value="${data.paymentDate1}" pattern="yyyy-MM-dd"/></th>
                    <th align="left">${data.payment2}</th>
                    <th align="left"><fmt:formatDate value="${data.paymentDate2}" pattern="yyyy-MM-dd"/></th>                    
                    <th align="left">${data.payment3}</th>
                    <th align="left"><fmt:formatDate value="${data.paymentDate3}" pattern="yyyy-MM-dd"/></th>
                    <th align="left">${data.taxRevenue}</th>
                  </tr>
                  </c:forEach>
                  </table>                
      			  </div>
          	  <div id="clear"></div>            
            </div>
            <!--产品详细信息 end-->
            
            <!--产品详细信息 begin-->	
    		<div class="titleBg">
            	<div class="fl"><img src="images/rightTitleLeft.jpg" alt="left" /></div>
            	<div class="fl title"><span class="marking1"></span>收入支出汇总&nbsp;&nbsp;
            		<input name="添 加" type="button" class="button" value="添 加" onclick="addIncome()"/>
            		<input name="修 改" type="button" class="button" value="修 改" onclick="editIncomes()"/>
            		<input name="删 除" type="button" class="button" value="删 除" onclick="delsellMultipleIncome()"/>
            	</div>
                <div class="fr"><img src="images/rightTitleRight.jpg" alt="left" /></div>
            </div>
            <div id="clear"></div>            
            <div class="rightBorder">            
                <div class="property1">
                <table width="100%" border="0" cellspacing="1" cellpadding="5" bgcolor="#dfe5e9">
                  <tr>
                  	<th width="3%" align="center"><input type="checkbox" name="iallSelectId" id="iallSelectId" onclick="judgmentChecjBox('iallSelectId','iid')" /></th>
                    <td width="37%" align="center" bgcolor="#dfe5e9">项目</td>
                    <td width="30%" align="center" bgcolor="#dfe5e9">金额</t>                        
                    <td width="30%" align="center" bgcolor="#dfe5e9">类别</td>
                  </tr>                    
                  <c:forEach var="income" items="${command.incomeList}">
                  <tr>
                    <th align="left"><input type="checkbox" value="${income.id}" name="iid"/></th>
                    <th align="left">${income.cooperFactory}</th>
                    <th align="left">${income.amount}</th>
                    <th align="left">${income.type==true?'收入':'支出'}</th>
                  </tr>
                  </c:forEach>
                  </table>                
      			  </div>
          	  <div id="clear"></div>            
            </div>
            
    	</div>    	
</form:form>
<!--产品详细信息 end-->
            
         
    <div id="win_temp" style="display:none">
	<div id="winCon_1">
	<table class="tabView" style="margin-top:5px">
		<tr><th width="100">合作工厂：</th><td colspan="3">
			<input type="text" name="cooperFactory" id="cooperFactory" value="" size="60" maxlength="200"/>
			<input type="hidden" name="orderId" id="orderId" value="${command.id}"/>
			<input type="hidden" name="factoryId" id="factoryId" value=""/>			
			<input type="button" onclick="browseSupplier()" value="选择" style="width:40px;"/>					
			</td>
		</tr>
		<tr><th>合同总金额：</th><td><input type="text" name="amount" id="amount" value="0" maxlength="10"/></td>
			<th>价格条款：</th><td><input type="text" name="terms" id="terms" value="" maxlength="10"/></td></tr>
		<tr><th>第1次付款：</th><td><input type="text" name="payment1" id="payment1" value="0"/></td>
			<th>时间：</th><td><input type="text" name="paymentDate1" id="paymentDate1" value="" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/></td></tr>			
		<tr><th>第2次付款：</th><td><input type="text" name="payment2" id="payment2" value="0" maxlength="10"/></td>
			<th>时间：</th><td><input type="text" name="paymentDate2" id="paymentDate2" value="" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/></td></tr>
		<tr><th>第3次付款：</th><td><input type="text" name="payment3" id="payment3" value="0" maxlength="10"/></td>
			<th>时间：</th><td><input type="text" name="paymentDate3" id="paymentDate3" value="" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/></td>
		</tr>
		<tr><th>退税收入：</th><td><input type="text" name="taxRevenue" id="taxRevenue" value="0"/></td>
			<th>&nbsp;</th><td>&nbsp;</td>
		</tr>
		<tr><td colspan="4" style="text-align:center;height:"><input type="button" value=" 提 交 " class="btn1" onclick="submitFactory()"/></td></tr>
	</table>
	</div>
	
	<div id="winCon_2">
	<table class="tabView" style="margin-top:5px">
		<tr><th width="100">项目：</th><td colspan="3">
			<input type="text" name="cooperFactory0" id="cooperFactory0" value="" size="60" maxlength="100"/>
			<input type="hidden" name="orderId0" id="orderId0" value="${command.id}"/>
			<input type="hidden" name="incomeId0" id="incomeId0" value=""/>								
			</td>
		</tr>
		<tr><th>金额：</th><td><input type="text" name="amount0" id="amount0" value="0" maxlength="10"/></td>
			<th>类别：</th><td>
			<input type="radio" name="type0" checked="checked"/>收入 <input type="radio" name="type0"/>支出 
			</td></tr>		
		<tr><td colspan="4" style="text-align:center;height:"><input type="button" value=" 提 交 " class="btn1" onclick="submitIncome()"/></td></tr>
	</table>
	</div>
	
	</div>
	
	
	
	
	
	<script src="<%=basePath%>js/win.js" type="text/javascript"></script>
<script  type="text/javascript">
function exportExcel(){			
	var ids = getSelectedCheckBoxValues('id');
	if(ids == "")
		alert("请先选择要导出的信息！");
	else {
		window.open("<%=basePath%>trade/exportExcel?t=4&ids="+ids);
	}
}
function addFactory(){
	WIN.show('<font size=5>添加工厂付款情况</font>',$('winCon_1'),{width:600,height:300});
}
function addIncome(){
	WIN.show('<font size=5>添加收入支出情况</font>',$('winCon_2'),{width:500,height:180});
}
function editFactory(id){
	WIN.show('<font size=5>修改工厂付款信息</font>',$('winCon_1'),{width:600,height:300});
	orderService.getFactoryById(id,function(data){
		$('factoryId').value=data.id;
		$('cooperFactory').value=data.cooperFactory;
		$('amount').value=data.amount;
		$('terms').value=data.terms;		
		$('payment1').value=data.payment1;
		$('payment2').value=data.payment2;
		$('payment3').value=data.payment3;
		
		$('paymentDate1').value=formatDate(data.paymentDate1);
		$('paymentDate2').value=formatDate(data.paymentDate2);
		$('paymentDate3').value=formatDate(data.paymentDate2);		
		$('taxRevenue').value=data.taxRevenue;	
		//$('order').value=data.order.id;
	})
}
function editIncome(id){
	WIN.show('<font size=5>修改收入支出信息</font>',$('winCon_2'),{width:500,height:180});
	orderService.getIncomeById(id,function(data){
		$('incomeId0').value=data.id;
		$('cooperFactory0').value=data.cooperFactory;
		$('amount0').value=data.amount;		
		if(data.type){$N('type0')[0].checked=true;}else{$N('type0')[1].checked=true;}
	})
}
function delsellMultiple(){			
	var objs = document.getElementsByName("fid");
	var ids='';	
	for(var i=0;i<objs.length;i++){
		if(objs[i].checked){
			ids+=objs[i].value+",";
		}
	}
	if(ids==''){
		alert("请先选择要操作的信息");
		return ;
	}
	ids = ids.substring(0,ids.length - 1);
	
	if(confirm("您确定要删除?")){
		if(ids == ""){
			alert("请先选择要删除的信息！");
			return false;
		}else{
			orderService.deleteFactoryByIds(ids,{
				callback:function(f){alert("删除成功");reload();},
				exceptionHandler:function(message){alert("删除失败，请重试");},
				errorHander:function(err){}
			})
		}
	}
}
function delsellMultipleIncome(){			
	var objs = document.getElementsByName("iid");
	var ids='';	
	for(var i=0;i<objs.length;i++){
		if(objs[i].checked){
			ids+=objs[i].value+",";
		}
	}
	if(ids==''){
		alert("请先选择要操作的收入支出信息");
		return ;
	}
	ids = ids.substring(0,ids.length - 1);
	
	if(confirm("您确定要删除?")){
		if(ids == ""){
			alert("请先选择要删除的信息！");
			return false;
		}else{
			orderService.deleteIncomeByIds(ids,{
				callback:function(f){alert("删除成功");reload();},
				exceptionHandler:function(message){alert("删除失败，请重试");},
				errorHander:function(err){}
			})
		}
	}
}

function editFactorys(){
	var objs = document.getElementsByName("fid");	
	var ids=0;
	var vas='';
	for(var i=0;i<objs.length;i++){
		if(objs[i].checked){
			ids++;
			vas=objs[i].value;			
		}
	}
	if(ids!=1){
		alert("请选择一条且只能选择一条信息进行编辑！");
		return ;
	}	
	if(vas==''){
		alert("请先选择要操作的信息");
		return ;
	}else{
		editFactory(vas);
	}	
}
function editIncomes(){
	var objs = document.getElementsByName("iid");	
	var ids=0;
	var vas='';
	for(var i=0;i<objs.length;i++){
		if(objs[i].checked){
			ids++;
			vas=objs[i].value;			
		}
	}
	if(ids!=1){
		alert("请选择一条且只能选择一条信息进行编辑！");
		return ;
	}	
	if(vas==''){
		alert("请先选择要操作的信息");
		return ;
	}else{
		editIncome(vas);
	}	
}

function submitFactory(){
	var data={
		id:			$('factoryId').value,
		order:   	{id:$('orderId').value},
		cooperFactory:	$('cooperFactory').value,
		amount:	$('amount').value,
		terms:		$('terms').value,
		payment1:	$('payment1').value,
		payment2:	$('payment2').value,
		payment3:	$('payment3').value,
		paymentDate1:  $('paymentDate1').value.trim()?new Date($('paymentDate1').value.trim().replace(/-/g,"/")):'',
		paymentDate2:  $('paymentDate2').value.trim()?new Date($('paymentDate2').value.trim().replace(/-/g,"/")):'',
		paymentDate3:  $('paymentDate3').value.trim()?new Date($('paymentDate3').value.trim().replace(/-/g,"/")):'',					
		taxRevenue:     $("taxRevenue").value
	}
	
	submit(data);
}
function submit(data){
	if(''==data.order){alert('订单信息不能为空');return;}
	if(''==cooperFactory){alert('合作工厂不能为空');return;}
	
	WIN.close();
	WIN.showpg();
	orderService.editFactory(data,{
		callback:function(f){WIN.closepg();alert("操作成功");reload();},
		exceptionHandler:function(message){WIN.closepg();alert(message);alert("操作失败，请重试");},
		errorHander:function(err){}
	})
}
function submitIncome(){
	var data={
		id:			$('incomeId0').value,
		order:   	{id:$('orderId0').value},
		type:		$N('type0')[0].checked,
		cooperFactory:	$('cooperFactory0').value,
		amount:	$('amount0').value,		
	}
	
	if(''==data.order){alert('订单信息不能为空');return;}
	if(''==data.cooperFactory){alert('项目信息不能为空');return;}
	
	WIN.close();
	WIN.showpg();
	orderService.editIncome(data,{
		callback:function(f){WIN.closepg();alert("操作成功");reload();},
		exceptionHandler:function(message){WIN.closepg();alert(message);alert("操作失败，请重试");},
		errorHander:function(err){}
	})
}
</script>
</body>
</html>
